#pragma once
#include<iostream>
#include<string>
#include<pthread.h>
#include<mutex>
#include<unistd.h>

namespace MutexModule
{
    class Mutex
    {
    public:
        Mutex()
        {
            pthread_mutex_init(&_mutex,nullptr);
        }

        void lock()
        {
            pthread_mutex_lock(&_mutex);
        }

        pthread_mutex_t* GetMutex()
        {
            return &_mutex;
        }

        void unlock()
        {
            pthread_mutex_unlock(&_mutex);
        }

        ~Mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }

    private:
        pthread_mutex_t _mutex;
    };

    class MutexGuard
    {
    public:
        MutexGuard(Mutex&mutex):_mutex(mutex)
        {
            _mutex.lock();
        }

        ~MutexGuard()
        {
            _mutex.unlock();
        }

    private:
        Mutex& _mutex;
    };  
};